package com.yzk.train.business.mq;

import com.alibaba.fastjson2.JSON;
import com.yzk.train.business.request.ConfirmOrderDoReq;
import com.yzk.train.business.service.ConfirmOrderService;
import com.yzk.train.common.constant.MQConstant;
import jakarta.annotation.Resource;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(topic = MQConstant.CONFIRM_ORDER, consumerGroup = MQConstant.PROJECT_GROUP)
public class ConfirmOrderConsumer implements RocketMQListener<String> {

    private static final Logger LOG = LoggerFactory.getLogger(ConfirmOrderConsumer.class);

    @Resource
    private ConfirmOrderService confirmOrderService;

    /**
     * 确认订单：异步选座
     *
     * @param message 消息体
     */
    @Override
    public void onMessage(String message) {
        ConfirmOrderDoReq req = JSON.parseObject(message, ConfirmOrderDoReq.class);
        MDC.put("LOG_ID", req.getLogId());
        LOG.info("收到【确认订单】消息：{}，开始消费", req);
        confirmOrderService.doConfirm(req);
    }

}
